import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { useRequest } from '@umijs/hooks';
import React, { useState, useRef, useCallback, useEffect } from 'react';

import { Input, Modal ,DatePicker, Select, Row, Col, } from 'antd';
import { queryCityInfo } from '../service';


const FormItem = Form.Item;
const { TextArea } = Input;
const { Option } = Select;

const UpdateForm = props => {
  const {updateData, updateModalVisible, form, onCancel, onSubmit: handleUpdate} = props
  const { data: selectData } = useRequest(queryCityInfo);

  // 保存
  const okHandle = () => {
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      handleUpdate({...updateData, ...fieldsValue});
    });
  };

  const formLayout = {
    labelCol: {
      span: 6,
    },
    wrapperCol: {
      span: 16,
    },
  };

  return (
    <Modal
      centered={true}
      destroyOnClose={true}
      title="编辑贵宾室"
      visible={updateModalVisible}
      onOk={okHandle}
      onCancel={() => onCancel()}
    >
      <FormItem
        {...formLayout}
        label="出发航站"
      >
        {form.getFieldDecorator('airpId', {
          initialValue: updateData.airpId,
          rules: [
            {
              required: true,
              message: '请选择出发航站！',
            },
          ],
        })(
          <Select
            style={{width: '100%'}}
            allowClear={true}
            showSearch
            placeholder="请选择"
            defaultActiveFirstOption={false}
            showArrow={false}
            filterOption={true}
            optionFilterProp="children"
            notFoundContent={null}
          >
            {selectData &&
              selectData.map((v, i) => {
                return (
                  <Option key={v.CITY3CODE}>{v.CITYNAME}-{v.CITY3CODE}</Option>
                )
              })
            }
          </Select>)}
      </FormItem>
      <FormItem
        {...formLayout}
        label="贵宾室"
      >
        {form.getFieldDecorator('roomName', {
          initialValue: updateData.roomName,
          rules: [
            {required: true, message: '请输入贵宾室！'},

          ],
        })(<Input placeholder="请输入" />)}
      </FormItem>
      <FormItem
        {...formLayout}
        label="扫码枪编号"
      >
        {form.getFieldDecorator('barcodeGun', {
          initialValue: updateData.barcodeGun,
          // rules: [
          //   {required: true, message: '请输入扫码枪编号！'},
          // ],
        })(<Input  placeholder="请输入" />)}
      </FormItem>
    </Modal>
  )

}

export default Form.create()(UpdateForm);
